import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 联系人
class HttpContactPersonService {
  /// 联系人列表
  static Future<Response> contactList(int contactId) {
    return BaseConfig.httpBase.get('/api/contact_persons', {
      'contact_id': contactId,
    });
  }

  /// 创建联系人
  static Future<Response> createContact(
    int contactId,
    String name,
    String countryCode,
    String phoneNumber,
    String email,
    String position,
    int isPrimary,
  ) {
    return BaseConfig.httpBase.postJson('/api/contact_persons', {
      "contact_id": contactId,
      "name": name,
      "country_code": countryCode,
      "phone_number": phoneNumber,
      "email": email,
      "position": position,
      "is_primary": isPrimary
    });
  }

  /// 显示联系人
  static Future<Response> showContact(int contact) {
    return BaseConfig.httpBase.get('/api/contact_persons/$contact', {});
  }

  /// 更新联系人
  static Future<Response> updateContact(
    int id,
    int contactId,
    String name,
    String countryCode,
    String phoneNumber,
    String email,
    String position,
    int isPrimary,
  ) {
    return BaseConfig.httpBase.putJson('/api/contact_persons/$id', {
      "contact_id": contactId,
      "name": name,
      "country_code": countryCode,
      "phone_number": phoneNumber,
      "email": email,
      "position": position,
      "is_primary": isPrimary
    });
  }

  /// 删除联系人
  static Future<Response> deleteContact(int contactId) {
    return BaseConfig.httpBase
        .deleteJson('/api/contact_persons/$contactId', {});
  }
}
